<?php

/*
Setting up Quests (admin_setup_quests.pro.php)
*/

$rank_check = "7";
include "../global.inc.php";

$explode_e_i = explode(", ", $easy_i);
$count_e_i = count($explode_e_i) - 1;

for ($a = 0; $a <= $count_e_i;)
{
	$findItem = fetch("SELECT * FROM items2 WHERE item_name = '$explode_e_i[$a]' AND game = '$game'");
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$explode_e_i[$a]\" does not exsist!")));
	}
	$a++;
}

$explode_e_p = explode(", ", $easy_p);
$count_e_p = count($explode_e_p) - 1;

for ($a = 0; $a <= $count_e_p;)
{
	$findItem = fetch("SELECT * FROM items2 WHERE item_name = '$explode_e_p[$a]' AND game = '$game'");
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$explode_e_p[$a]\" does not exsist!")));
	}
	$a++;
}

$explode_m_i = explode(", ", $med_i);
$count_m_i = count($explode_m_i) - 1;

for ($a = 0; $a <= $count_m_i;)
{
	$findItem = fetch("SELECT * FROM items2 WHERE item_name = '$explode_m_i[$a]' AND game = '$game'");
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$explode_m_i[$a]\" does not exsist!")));
	}
	$a++;
}

$explode_m_p = explode(", ", $med_p);
$count_m_p = count($explode_m_p) - 1;

for ($a = 0; $a <= $count_m_p;)
{
	$findItem = fetch("SELECT id FROM items2 WHERE item_name = '$explode_m_p[$a]' AND game = '$game'");
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$explode_m_p[$a]\" does not exsist!")));
	}
	$a++;
}

$explode_h_i = explode(", ", $hard_i);
$count_h_i = count($explode_h_i) - 1;

for ($a = 0; $a <= $count_h_i;)
{
	$findItem = fetch("SELECT id FROM items2 WHERE item_name = '$explode_h_i[$a]' AND game = '$game'");
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$explode_h_i[$a]\" does not exsist!")));
	}
	$a++;
}

$explode_h_p = explode(", ", $hard_p);
$count_h_p = count($explode_h_p) - 1;

for ($a = 0; $a <= $count_h_p;)
{
	$findItem = fetch("SELECT id FROM items2 WHERE item_name = '$explode_h_p[$a]' AND game = '$game'");
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$explode_h_p[$a]\" does not exsist!")));
	}
	$a++;
}

if ($def_e)
{
	$findItem = fetch("SELECT id FROM items2 WHERE item_name = '$def_e' AND game = '$game'"); 
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$def_e\" does not exsist!")));
	}
}

if ($def_i)
{
	$findItem = fetch("SELECT id FROM items2 WHERE item_name = '$def_i' AND game = '$game'"); 
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$def_i\" does not exsist!")));
	}
}

if ($def_h)
{
	$findItem = fetch("SELECT id FROM items2 WHERE item_name = '$def_h' AND game = '$game'"); 
	if (!$findItem[id])
	{
		die(header(error("admin_setup_quests.php?game=$game","The item \"$def_h\" does not exsist!")));
	}
}

mysql_query("DELETE FROM quest_items WHERE game = '$game'");
mysql_query("INSERT INTO quest_items (game, easy_i, easy_p, easy_pts, med_i, med_p, med_pts, hard_i, hard_p, hard_pts, def_e, def_i, def_h) VALUES ('$game', '$easy_i', '$easy_p', '$easy_pts_min,$easy_pts_max', '$med_i', '$med_p', '$med_pts_min,$med_pts_max', '$hard_i', '$hard_p', '$hard_pts_min,$hard_pts_max', '$def_e', '$def_i', '$def_h')");

header(error("admin_setup_quests.php?game=$game","The game has been setup! You can now <a href=../quests.php?game=$game>play</a>!!"));
?>
